package com.emersonprocess.danpacmobile.custom;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import android.widget.LinearLayout;

import com.emersonprocess.danpacmobile.R;

public class FlipReports extends LinearLayout {

	private Animation animationFlip1;
	private Animation animationFlip2;
	private boolean isBackOfCardShowing = true;

	private AnimationListener animListener;
	private Context mContext;

	public FlipReports(Context context, AttributeSet attrs) {
		super(context, attrs);
		mContext = context;

		setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				setEnabled(false);
				clearAnimation();
				setAnimation(animationFlip1);
				startAnimation(animationFlip1);

			}
		});

		animListener = new AnimationListener() {

			@Override
			public void onAnimationStart(Animation animation) {
				// TODO Auto-generated method stub

			}

			@Override
			public void onAnimationRepeat(Animation animation) {
				// TODO Auto-generated method stub

			}

			@Override
			public void onAnimationEnd(Animation animation) {
				if (animation == animationFlip1) {
					clearAnimation();
					setAnimation(animationFlip2);
					startAnimation(animationFlip2);
				} else {
					isBackOfCardShowing = !isBackOfCardShowing;
					setEnabled(true);

				}
			}
		};

		animationFlip1 = AnimationUtils.loadAnimation(mContext, R.anim.to_middle);
		animationFlip1.setAnimationListener(animListener);
		animationFlip2 = AnimationUtils.loadAnimation(mContext, R.anim.from_middle);
		animationFlip2.setAnimationListener(animListener);
	}

}
